package com.shopping.util;

import org.springframework.stereotype.Component;
import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 加密
 */
@Component
public class MD5Util {

    public String getEncoderStr(String str){
        String enStr = "";
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        }catch (NoSuchAlgorithmException e){
            e.printStackTrace();
        }
        BASE64Encoder base64Encoder = new BASE64Encoder();
        try {
            enStr = base64Encoder.encode(md5.digest(str.getBytes("utf-8")));
        }catch (UnsupportedEncodingException e){
            e.printStackTrace();
        }
        return enStr;
    }

}